package com.ymatou.iapi.productmanager.testcase;

import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.productmanager.parameter.QueryBatchProductListBean;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.iapi.productmanager.service.QueryBatchProductListCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.utils.EnvSetup;
/**
*查询待批量修改的商品列表
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_QueryBatchProductList{
	private static QueryBatchProductListBean querybatchproductlistBean = new QueryBatchProductListBean();
	private static QueryBatchProductListCall querybatchproductlistCall = new QueryBatchProductListCall();
	private static Integer sellerId = Integer.valueOf(EnvSetup.getData("productpriceSellerId"));
	private static String sellerName = EnvSetup.getData("productpriceSellerName");	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询待批量修改的商品列表");
	}

	@Before
	public void caseUp() {
		querybatchproductlistBean=new QueryBatchProductListBean();
		querybatchproductlistCall=new QueryBatchProductListCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(querybatchproductlistCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryBatchProductList_001() {
		Logger.start(true,"查询待批量修改的商品列表,按二级类目来查询");
		try {
			querybatchproductlistBean.setIsOnSale(false);
			querybatchproductlistBean.setSellerId(sellerId);
			querybatchproductlistBean.setThirdCategoryId(1003);
			querybatchproductlistCall.setData(querybatchproductlistBean);
			JSONObject ret = querybatchproductlistCall.callAndGetReturnData(querybatchproductlistBean);			
			JSONArray jsonArray = ret.getJSONObject("Data").getJSONArray("productList");
			Logger.verifyEquals("200", ret.get("Code").toString(), "验证Code");
			for(int i=0;i<jsonArray.length();i++){
				Integer thirdCategoryId = querybatchproductlistCall.getProductList().get(i).getThirdCategoryId();
				Logger.verifyEquals(querybatchproductlistBean.getThirdCategoryId(), thirdCategoryId, "验证ThirdCategoryId");
			}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryBatchProductList_002() {
		Logger.start(true,"查询待批量修改的商品列表,按品牌名称来查询");
		try {
			querybatchproductlistBean.setIsOnSale(false);
			querybatchproductlistBean.setSellerId(sellerId);
			querybatchproductlistBean.setBrandName("Nike");
			querybatchproductlistCall.setData(querybatchproductlistBean);
			JSONObject ret = querybatchproductlistCall.callAndGetReturnData(querybatchproductlistBean);			
			JSONArray jsonArray = ret.getJSONObject("Data").getJSONArray("productList");
			Logger.verifyEquals("200", ret.get("Code").toString(), "验证Code");
			for(int i=0;i<jsonArray.length();i++){
				String brandName = querybatchproductlistCall.getProductList().get(i).getBrandName();
				Logger.verifyEquals(true, brandName.contains(querybatchproductlistBean.getBrandName()), "验证brandName");
			}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryBatchProductList_003() {
		Logger.start(true,"查询待批量修改的商品列表,按商品名称来查询");
		try {
			querybatchproductlistBean.setIsOnSale(false);
			querybatchproductlistBean.setSellerId(sellerId);
			querybatchproductlistBean.setProductName("测试");
			querybatchproductlistCall.setData(querybatchproductlistBean);
			JSONObject ret = querybatchproductlistCall.callAndGetReturnData(querybatchproductlistBean);			
			JSONArray jsonArray = ret.getJSONObject("Data").getJSONArray("productList");
			Logger.verifyEquals("200", ret.get("Code").toString(), "验证Code");
			for(int i=0;i<jsonArray.length();i++){
				String productName = querybatchproductlistCall.getProductList().get(i).getProductName();
				Logger.verifyEquals(true, productName.contains(querybatchproductlistBean.getProductName()), "验证productName");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryBatchProductList_004() {
		Logger.start(true,"查询待批量修改的商品列表,按商品名称和商品品牌来查询");
		try {
			querybatchproductlistBean.setIsOnSale(false);
			querybatchproductlistBean.setSellerId(sellerId);
			querybatchproductlistBean.setProductName("测试");
			querybatchproductlistBean.setBrandName("Nike");
			querybatchproductlistCall.setData(querybatchproductlistBean);
			JSONObject ret = querybatchproductlistCall.callAndGetReturnData(querybatchproductlistBean);			
			JSONArray jsonArray = ret.getJSONObject("Data").getJSONArray("productList");
			Logger.verifyEquals("200", ret.get("Code").toString(), "验证Code");
			for(int i=0;i<jsonArray.length();i++){
				String productName = querybatchproductlistCall.getProductList().get(i).getProductName();
				Logger.verifyEquals(true, productName.contains(querybatchproductlistBean.getProductName()), "验证productName");
				String brandName = querybatchproductlistCall.getProductList().get(i).getBrandName();
				Logger.verifyEquals(true, brandName.contains(querybatchproductlistBean.getBrandName()), "验证brandName");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryBatchProductList_005() {
		Logger.start(true,"查询待批量修改的商品列表,按商品名称和商品分类来查询");
		try {
			querybatchproductlistBean.setIsOnSale(false);
			querybatchproductlistBean.setSellerId(sellerId);
			querybatchproductlistBean.setProductName("测试");
			querybatchproductlistBean.setThirdCategoryId(1003);
			querybatchproductlistCall.setData(querybatchproductlistBean);
			JSONObject ret = querybatchproductlistCall.callAndGetReturnData(querybatchproductlistBean);			
			JSONArray jsonArray = ret.getJSONObject("Data").getJSONArray("productList");
			Logger.verifyEquals("200", ret.get("Code").toString(), "验证Code");
			for(int i=0;i<jsonArray.length();i++){
				String productName = querybatchproductlistCall.getProductList().get(i).getProductName();
				Logger.verifyEquals(true, productName.contains(querybatchproductlistBean.getProductName()), "验证productName");
				Integer thirdCategoryId = querybatchproductlistCall.getProductList().get(i).getThirdCategoryId();
				Logger.verifyEquals(querybatchproductlistBean.getThirdCategoryId(), thirdCategoryId, "验证ThirdCategoryId");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryBatchProductList_006() {
		Logger.start(true,"查询待批量修改的商品列表,按商品品牌和商品分类来查询");
		try {
			querybatchproductlistBean.setIsOnSale(false);
			querybatchproductlistBean.setSellerId(sellerId);
			querybatchproductlistBean.setBrandName("Nike");
			querybatchproductlistBean.setThirdCategoryId(1003);
			querybatchproductlistCall.setData(querybatchproductlistBean);
			JSONObject ret = querybatchproductlistCall.callAndGetReturnData(querybatchproductlistBean);			
			JSONArray jsonArray = ret.getJSONObject("Data").getJSONArray("productList");
			Logger.verifyEquals("200", ret.get("Code").toString(), "验证Code");
			for(int i=0;i<jsonArray.length();i++){
				Integer thirdCategoryId = querybatchproductlistCall.getProductList().get(i).getThirdCategoryId();
				Logger.verifyEquals(querybatchproductlistBean.getThirdCategoryId(), thirdCategoryId, "验证ThirdCategoryId");
				String brandName = querybatchproductlistCall.getProductList().get(i).getBrandName();
				Logger.verifyEquals(true, brandName.contains(querybatchproductlistBean.getBrandName()), "验证brandName");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryBatchProductList_007() {
		Logger.start(true,"查询待批量修改的商品列表,按商品品牌、商品分类和商品名称来查询");
		try {
			querybatchproductlistBean.setIsOnSale(false);
			querybatchproductlistBean.setSellerId(sellerId);
			querybatchproductlistBean.setBrandName("Nike");
			querybatchproductlistBean.setThirdCategoryId(1003);
			querybatchproductlistBean.setProductName("测试");
			querybatchproductlistCall.setData(querybatchproductlistBean);
			JSONObject ret = querybatchproductlistCall.callAndGetReturnData(querybatchproductlistBean);			
			JSONArray jsonArray = ret.getJSONObject("Data").getJSONArray("productList");
			Logger.verifyEquals("200", ret.get("Code").toString(), "验证Code");
			for(int i=0;i<jsonArray.length();i++){
				Integer thirdCategoryId = querybatchproductlistCall.getProductList().get(i).getThirdCategoryId();
				Logger.verifyEquals(querybatchproductlistBean.getThirdCategoryId(), thirdCategoryId, "验证ThirdCategoryId");
				String brandName = querybatchproductlistCall.getProductList().get(i).getBrandName();
				Logger.verifyEquals(true, brandName.contains(querybatchproductlistBean.getBrandName()), "验证brandName");
				String productName = querybatchproductlistCall.getProductList().get(i).getProductName();
				Logger.verifyEquals(true, productName.contains(querybatchproductlistBean.getProductName()), "验证productName");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}